/**
 * 作者: hxl
 * 日期: 2025-07-08 11:20:11
 * 备注: 用户联盟乱斗干员快照表（常驻活动）
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserUnionScufflePartner;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserUnionScufflePartnerWeekModel extends BaseModel implements Model {
    public static final String LISTKEY = "group_list_key.partner_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_NOT;// 数据入库类型 不入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 玩家id
    protected long weekResetTime; // 战斗id
    protected long userId; // 玩家id
    protected int partnerId; // 干员id
    protected long totalPower; // 总战力
    protected int weaponId; // 武器id
    protected String groupListKey = ""; // 分组key
    protected long memberId; // 成员id

    public void reset() {
    }

    protected String getKey() {
        return "UserUnionScufflePartnerWeek." + groupListKey + "." + partnerId;
    }

    protected String getListKey() {
        return "UserUnionScufflePartnerWeek." + groupListKey;
    }

    protected String getListItemKey() {
        return partnerId + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_union_scuffle_partner_week"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 玩家id
        obj.put("weekResetTime", weekResetTime); // 战斗id
        obj.put("userId", userId); // 玩家id
        obj.put("partnerId", partnerId); // 干员id
        obj.put("totalPower", totalPower); // 总战力
        obj.put("weaponId", weaponId); // 武器id
        obj.put("groupListKey", groupListKey); // 分组key
        obj.put("memberId", memberId); // 成员id
        return obj;
    }

    public PBUserUnionScufflePartner.Builder takeInitBuilder() {
        PBUserUnionScufflePartner.Builder sb = PBUserUnionScufflePartner.newBuilder();
        if (partnerId != 0) {
            sb.setPartnerId(partnerId);
        }
        if (totalPower != 0) {
            sb.setTotalPower(totalPower);
        }
        if (weaponId != 0) {
            sb.setWeaponId(weaponId);
        }
        return sb;
    }

    public PBUserUnionScufflePartner.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserUnionScufflePartner.Builder sb = PBUserUnionScufflePartner.newBuilder();
        if (isFieldUpdate("partnerId")) {
            sb.setPartnerId(partnerId);
        }
        if (isFieldUpdate("totalPower")) {
            sb.setTotalPower(totalPower);
        }
        if (isFieldUpdate("weaponId")) {
            sb.setWeaponId(weaponId);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getWeekResetTime() {
        return weekResetTime;
    }

    public void putWeekResetTime(long weekResetTime) {
        if (this.weekResetTime != weekResetTime) {
            this.weekResetTime = weekResetTime;
            updateRedisHashField(getKey(), "weekResetTime", this.weekResetTime);
        }
    }

    public void addWeekResetTime(long value) {
        this.weekResetTime += value;
        updateRedisHashField(getKey(), "weekResetTime", this.weekResetTime);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public int getPartnerId() {
        return partnerId;
    }

    public void putPartnerId(int partnerId) {
        if (this.partnerId != partnerId) {
            this.partnerId = partnerId;
            updateRedisHashField(getKey(), "partnerId", this.partnerId);
        }
    }

    public void addPartnerId(int value) {
        this.partnerId += value;
        updateRedisHashField(getKey(), "partnerId", this.partnerId);
    }

    public long getTotalPower() {
        return totalPower;
    }

    public void putTotalPower(long totalPower) {
        if (this.totalPower != totalPower) {
            this.totalPower = totalPower;
            updateRedisHashField(getKey(), "totalPower", this.totalPower);
        }
    }

    public void addTotalPower(long value) {
        this.totalPower += value;
        updateRedisHashField(getKey(), "totalPower", this.totalPower);
    }

    public int getWeaponId() {
        return weaponId;
    }

    public void putWeaponId(int weaponId) {
        if (this.weaponId != weaponId) {
            this.weaponId = weaponId;
            updateRedisHashField(getKey(), "weaponId", this.weaponId);
        }
    }

    public void addWeaponId(int value) {
        this.weaponId += value;
        updateRedisHashField(getKey(), "weaponId", this.weaponId);
    }

    public String getGroupListKey() {
        return groupListKey;
    }

    public void putGroupListKey(String groupListKey) {
        if (!this.groupListKey.equals(groupListKey)) {
            this.groupListKey = groupListKey;
            updateRedisHashField(getKey(), "groupListKey", this.groupListKey);
        }
    }

    public long getMemberId() {
        return memberId;
    }

    public void putMemberId(long memberId) {
        if (this.memberId != memberId) {
            this.memberId = memberId;
            updateRedisHashField(getKey(), "memberId", this.memberId);
        }
    }

    public void addMemberId(long value) {
        this.memberId += value;
        updateRedisHashField(getKey(), "memberId", this.memberId);
    }

}